

function loginUp(champs)
{
	var icon = getE("iconLogin");
	var cond = champs.value.length >= 4;
	setClass(champs, icon, cond);
	return cond;
}

function emailUp(champs)
{
	var icon = getE("iconEmail");
	var regexMail = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	var cond = regexMail.test(champs.value);
	setClass(champs, icon, cond);
	return cond;
}

function pwd1Up(champs)
{
	var icon = getE("iconPwd1");
	var cond = champs.value.length >= 6;
	setClass(champs, icon, cond);
	pwd2Up(getE('ipwd2'));
	return cond;
}

function pwd2Up(pwd2)
{
	var pwd1 = getE("ipwd1");
	var icon = getE("iconPwd2");
	var cond = pwd2.value.length >= 6 && pwd2.value == pwd1.value;
	setClass(pwd2, icon, cond);
	return cond;
}

function verifForm()
{
	var _log = loginUp(getE('ilogin'));
	var _email = emailUp(getE('iemail'));
	var _pwd1 = pwd1Up(getE('ipwd1'));
	var _pwd2 = pwd2Up(getE('ipwd2'));


	if(_log && _email && _pwd1 && _pwd2)
	{
		return true;
	}
	else if(!_log)
	{
		msgErreur('Le login doit comporté au moins 4 caractères!');
		return false;
	}
	else if(!_email) 
	{
		msgErreur('Email non valide!');
		return false;
	}
	else if(!_pwd1)
	{
		msgErreur('Le mot de passe doit comporté au moins 6 caractères!');
		return false;
	}
	else if(!_pwd2)
	{
		msgErreur('Les deux mots de passe ne sont pas identiques!');
		return false;
	}
	else
	{
		msgErreur('Formaulaire non valide');
		return false;
	}
}

function verifFormMdpMail()
{
	var _email = emailUp(getE('iemail'));

	if(_email)
	{
		return true;
	}
	else
	{
		msgErreur('Email non valide!');
		return false;
	}
	
}

function resetForm()
{
	//réinitialisation des class
	setClass(getE('ilogin'), getE('iconLogin'), null);
	setClass(getE('iemail'), getE('iconEmail'), null);
	setClass(getE('ipwd1') , getE('iconPwd1') , null);
	setClass(getE('ipwd2') , getE('iconPwd2') , null);
	msgErreur('');
}

function resetFormCo()
{
	var err = document.getElementById('erreurCo')
	err.innerHTML = '';
}

function msgErreur(msg)
{
	var err = document.getElementById('erreur')
	err.innerHTML = msg;
	if(msg.length != 0)
		err.parentNode.parentNode.setAttribute('class', 'alert alert-block alert-error fade in');
	else
		err.parentNode.parentNode.setAttribute('class', '');
}

function getE(elt)
{
	return document.getElementById(elt);
} 

function setClass(champs, icon, ok)
{
	var class1, class2;
	if(ok==null){
		class1 = '';
		class2 = 'control-group';
	}
	else if(ok){
		class1 = 'icon-ok';
		class2 = 'control-group success';
	}
	else{
		class1 = 'icon-remove';
		class2 = 'control-group error';
	}

	icon.setAttribute('class', class1);
	champs.parentNode.parentNode.parentNode.setAttribute('class', class2);
}